<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%@ include file="/common/grid/jqGrid.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="">
	
  </head>
  
  <body>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'保存列表字段'}]"/>
    			<jsp:param name="width" value="70%"/>
    		</jsp:include>
    		
    		<s:hidden id="fieldId" name="lf.id"></s:hidden>
    		<s:hidden id="listId" name="lf.listDefine.id"></s:hidden>
    		
    		<table width="100%" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
    			<tr bgcolor="#FFFFFF">
    				<td width="20%" align="right" class="label">
    					字段名：
    				</td>
    				<td width="30%" align="left">
    					<s:textfield name="lf.fieldName" id="fieldName" cssStyle="width:98%" maxlength="20"></s:textfield>
    				</td>
    				<td width="20%" align="right" class="label">
    					头描述：
    				</td>
    				<td width="30%" align="left">
    					<s:textfield name="lf.chineseName" id="chineseName" cssStyle="width:98%" maxlength="20"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					字段索引：
    				</td>
    				<td align="left">
    					<s:textfield name="lf.fieldIndex" id="fieldIndex" cssStyle="width:98%" maxlength="20"></s:textfield>
    				</td>
    				<td align="right" class="label">
    					允许排序：
    				</td>
    				<td align="left">
    					<s:select list='#{"N":"否", "Y":"是"}' name="lf.sortable" id="sortable" cssStyle="width:100px"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					宽度：
    				</td>
    				<td align="left">
    					<s:textfield name="lf.fieldWidth" id="fieldWidth" cssStyle="width:98%" maxlength="5"></s:textfield>
    				</td>
    				<td align="right" class="label">
    					字段类型：
    				</td>
    				<td align="left">
    					<s:select list='#{"normal":"正常", "js":"JS代码"}' name="lf.fieldType" id="fieldType" cssStyle="width:100px" onchange="fieldTypeChange()"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF" id="jsCodeTr" style="display:none;">
    				<td align="right" class="label">
    					JS代码：
    				</td>
    				<td align="left" colspan="3">
    					function..(cellVal, options, row) {
    					<br/>
    					<s:textarea name="lf.script" id="script" cssStyle="width:98%; height:200px"></s:textarea>
    					<br/>
    					}
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					数据类型：
    				</td>
    				<td align="left">
    					<s:select list='#{"String":"文本", "Date":"日期"}' name="lf.dataType" id="dataType" cssStyle="width:100px" onchange="dataTypeChange()"></s:select>
    				</td>
    				<td align="right" class="label">
    					日期格式：
    				</td>
    				<td align="left">
    					<s:select list="dateFormatList" listKey="value" listValue="label" headerKey="" headerValue="--请选择--" name="lf.dateFormat" id="dateFormat" cssStyle="width:180px"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					排序：
    				</td>
    				<td align="left">
    					<s:textfield name="lf.sort" id="sort" cssStyle="width:98%" maxlength="3"></s:textfield>
    				</td>
    				<td></td>
    				<td></td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="保存" class="btn" onclick="saveListField()" />
    				</td>
    			</tr>
    		</table>
    	</s:form>
    
    <script type="text/javascript">
	$(function(){
		fieldTypeChange();
		dataTypeChange();
	});
    
    function saveListField()
    {
        var fieldName = $('#fieldName');
        var chineseName = $('#chineseName');
        var sort = $('#sort');
        if(!isNotNull(fieldName.val()))
        {
			showMsg('字段名不能为空。', function(){
				fieldName.focus();
			});
			return;
        }
        if(!isNotNull(chineseName.val()))
        {
			showMsg('头描述不能为空。', function(){
				chineseName.focus();
			});
			return;
        }
        if(checkInteger(sort) == false)
        {
        	showMsg('排序必须为整数。', function(){
        		sort.focus();
			});
			return;
        }
		var url = 'inner/core/saveListField.action';
		ajaxAction(url, 'post', 'frm', false, function(){
			window.opener.searchThis();
			window.close();
		});
    }

    function fieldTypeChange()
    {
		var fieldType = $('#fieldType');
		var jsCodeTr = $('#jsCodeTr');
		var script = $('#script');
		if('normal' == fieldType.val())
		{
			jsCodeTr.css('display', 'none');
			script.val('');
		}
		else if('js' == fieldType.val())
		{
			jsCodeTr.css('display', 'block');
		}
    }

    function dataTypeChange()
    {
    	var dataType = $('#dataType');
    	var dateFormat = $('#dateFormat');
    	if('String' == dataType.val())
    	{
    		dateFormat.val('');
    		dateFormat.attr('disabled', true);
        }
    	else if('Date' == dataType.val())
    	{
    		dateFormat.attr('disabled', false);
        }
    }
    </script>
  </body>
</html>
